package com.ly.hotel.common;

import java.io.File;
import java.util.Locale;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

public class SharedPreferencesConfig {
	public static String TV_MODE_ADA_ATV = "ADA_ATV";//安卓安的模拟电视
	public static String MOVIE_MODE_PRE = "PRE";//普瑞尔的电影服务器
	public static String MOVIE_MODE_IPMOVIE = "IPMOVIE";//第三方的网络电影
	public static String DEBUG_ON = "ON";
	public static String DEBUG_OFF = "OFF";
	
	//如果本地没有配置文件，就保存默认的，这样如果会所的版本是写死配置的话，也可以再升级后的spa程序中使用
	public static void initSharedPreferencesConfigFile(Context context){

		File f1 = new File("/data/data/com.ly.hotel/shared_prefs/spaserverconfig.xml");
		if(!f1.exists()){
			setSpaServer(context, getSpaServer(context));
		}
		
		File f2 = new File("/data/data/com.ly.hotel/shared_prefs/serialbaudconfig.xml");
		if(!f2.exists()){
			setSerialBaud(context, getSerialBaud(context));
		}
		
	}

	public static boolean getSpaBootFlag(Context context) {
		SharedPreferences sp = context.getSharedPreferences("spaserverconfig", Context.MODE_PRIVATE);
		boolean flag = sp.getBoolean("FIRST", true);
		return flag;
	}
	
	public static void setSpaBootFlag(Context context, boolean flag) { 
		SharedPreferences sp= context.getSharedPreferences("spaserverconfig",Activity.MODE_PRIVATE); 
		SharedPreferences.Editor editor = sp.edit();
		//用putString的方法保存数据 
		editor.putBoolean("FIRST", flag); 
		//提交当前数据 
		editor.commit(); 
	}
	
	public static String getSpaServer(Context context) {
		SharedPreferences sp = context.getSharedPreferences("spaserverconfig", Context.MODE_PRIVATE);
		String ip = sp.getString("spaServer", Constants.DEFAULT_SPA_SERVER);
		return ip;
	}
	
	public static void setSpaServer(Context context, String ip) { 
		SharedPreferences sp= context.getSharedPreferences("spaserverconfig",Activity.MODE_PRIVATE); 
		SharedPreferences.Editor editor = sp.edit();
		//用putString的方法保存数据 
		editor.putString("spaServer", ip); 
		//提交当前数据 
		editor.commit(); 
	}
	
	public static int getSerialBaud(Context context) {
		SharedPreferences sp = context.getSharedPreferences("serialbaudconfig", Context.MODE_PRIVATE);
		int baud = sp.getInt("serialBaud", Constants.DEFAULT_SERIAL_BAUD);
		return baud;
	}
	
	public static void setSerialBaud(Context context, int baud) { 
		SharedPreferences sp= context.getSharedPreferences("serialbaudconfig",Activity.MODE_PRIVATE); 
		SharedPreferences.Editor editor = sp.edit();
		//用putString的方法保存数据 
		editor.putInt("serialBaud", baud); 
		//提交当前数据 
		editor.commit(); 
	}

	public static String getLastSpaVersion(Context context) {
		SharedPreferences sp = context.getSharedPreferences("conf", Context.MODE_PRIVATE);
		String date = sp.getString("LastSpaVersion", "");
		return date;
	}
	
	public static void setLastSpaVersion(Context context, String version) { 
		SharedPreferences sp= context.getSharedPreferences("conf",Activity.MODE_PRIVATE); 
		SharedPreferences.Editor editor = sp.edit();
		//用putString的方法保存数据 
		editor.putString("LastSpaVersion", version); 
		//提交当前数据 
		editor.commit(); 
	}


	public static String getScreenSize(Context context) {
		SharedPreferences sp = context.getSharedPreferences("conf", Context.MODE_PRIVATE);
		String date = sp.getString("ScreenSize", "");
		return date;
	}
	
	public static void setScreenSize(Context context, String date) { 
		SharedPreferences sp= context.getSharedPreferences("conf",Activity.MODE_PRIVATE); 
		SharedPreferences.Editor editor = sp.edit();
		//用putString的方法保存数据 
		editor.putString("ScreenSize", date); 
		//提交当前数据 
		editor.commit(); 
	}

	//获取app的模式，是进入spa，还是进入呼叫大屏显示
	public static String getAppMode(Context context) {
		SharedPreferences sp = context.getSharedPreferences("conf", Context.MODE_PRIVATE);
		String date = sp.getString("appMode", "hotel");//默认是进入spa
		return date;
	}
	
	public static void setAppMode(Context context, String mode) { 
		SharedPreferences sp= context.getSharedPreferences("conf",Activity.MODE_PRIVATE); 
		SharedPreferences.Editor editor = sp.edit();
		//用putString的方法保存数据 
		editor.putString("appMode", mode); 
		//提交当前数据 
		editor.commit(); 
	}
	
	public static String getLanguage(Context context) {
		SharedPreferences sp = context.getSharedPreferences("conf", Context.MODE_PRIVATE);
		String date = sp.getString("lang", Locale.SIMPLIFIED_CHINESE.toString());//默认是进入spa
		return date;
	}
	
	public static void setLanguage(Context context, String lang) { 
		SharedPreferences sp= context.getSharedPreferences("conf",Activity.MODE_PRIVATE); 
		SharedPreferences.Editor editor = sp.edit();
		//用putString的方法保存数据 
		editor.putString("lang", lang); 
		//提交当前数据 
		editor.commit(); 
	}
	
	public static String getBottomText(Context context) {
		SharedPreferences sp = context.getSharedPreferences("conf", Context.MODE_PRIVATE);
		String mode = sp.getString("bottomText", "");
		return mode;
	}

	//设置底部文字，用于存储定制界面
	public static void setBottomText(Context context, String user) {
		SharedPreferences sp= context.getSharedPreferences("conf",Activity.MODE_PRIVATE);
		SharedPreferences.Editor editor = sp.edit();
		editor.putString("bottomText", user);
		editor.commit();
	}

	public static String getHomeSort(Context context) {
		SharedPreferences sp = context.getSharedPreferences("conf", Context.MODE_PRIVATE);
		String mode = sp.getString("homeSort", "");
		return mode;
	}

	//设置底部顺序，用于存储定制界面
	public static void setHomeSort(Context context, String str) {
		SharedPreferences sp= context.getSharedPreferences("conf",Activity.MODE_PRIVATE);
		SharedPreferences.Editor editor = sp.edit();
		editor.putString("homeSort", str);
		editor.commit();
	}

	public static String getInterfaceType(Context context) {
		SharedPreferences sp = context.getSharedPreferences("conf", Context.MODE_PRIVATE);
		String mode = sp.getString("interType", "");
		return mode;
	}

	//设置接口服务器Ip
	public static void setInterfaceType(Context context, String str) {
		SharedPreferences sp= context.getSharedPreferences("conf",Activity.MODE_PRIVATE);
		SharedPreferences.Editor editor = sp.edit();
		editor.putString("interType", str);
		editor.commit();
	}


	public static String getInterfaceIp(Context context) {
		SharedPreferences sp = context.getSharedPreferences("conf", Context.MODE_PRIVATE);
		String mode = sp.getString("interIp", "");
		return mode;
	}

	//设置接口服务器Ip
	public static void setInterfaceIp(Context context, String str) {
		SharedPreferences sp= context.getSharedPreferences("conf",Activity.MODE_PRIVATE);
		SharedPreferences.Editor editor = sp.edit();
		editor.putString("interIp", str);
		editor.commit();
	}

	public static String getInterfacePort(Context context) {
		SharedPreferences sp = context.getSharedPreferences("conf", Context.MODE_PRIVATE);
		String mode = sp.getString("interPort", "");
		return mode;
	}

	//设置接口服务器端口
	public static void setInterfacePort(Context context, String str) {
		SharedPreferences sp= context.getSharedPreferences("conf",Activity.MODE_PRIVATE);
		SharedPreferences.Editor editor = sp.edit();
		editor.putString("interPort", str);
		editor.commit();
	}

	public static String getRoomNo(Context context) {
		SharedPreferences sp = context.getSharedPreferences("conf", Context.MODE_PRIVATE);
		String mode = sp.getString("roomNo", "");
		return mode;
	}

	//设置房间号
	public static void setRoomNo(Context context, String str) {
		SharedPreferences sp= context.getSharedPreferences("conf",Activity.MODE_PRIVATE);
		SharedPreferences.Editor editor = sp.edit();
		editor.putString("roomNo", str);
		editor.commit();
	}

	public static String getAreaId(Context context) {
		SharedPreferences sp = context.getSharedPreferences("conf", Context.MODE_PRIVATE);
		String mode = sp.getString("areaId", "");
		return mode;
	}

	//设置地区Id
	public static void setAreaId(Context context, String str) {
		SharedPreferences sp= context.getSharedPreferences("conf",Activity.MODE_PRIVATE);
		SharedPreferences.Editor editor = sp.edit();
		editor.putString("areaId", str);
		editor.commit();
	}

	public static String getAreaName(Context context) {
		SharedPreferences sp = context.getSharedPreferences("conf", Context.MODE_PRIVATE);
		String mode = sp.getString("areaName", "");
		return mode;
	}

	//设置接口服务器Ip
	public static void setAreaName(Context context, String str) {
		SharedPreferences sp= context.getSharedPreferences("conf",Activity.MODE_PRIVATE);
		SharedPreferences.Editor editor = sp.edit();
		editor.putString("areaName", str);
		editor.commit();
	}

	public static String getDefaultMessage(Context context) {
		SharedPreferences sp = context.getSharedPreferences("conf", Context.MODE_PRIVATE);
		String mode = sp.getString("defaultMsg", "");
		return mode;
	}

	//设置默认消息
	public static void setDefaultMessage(Context context, String str) {
		SharedPreferences sp= context.getSharedPreferences("conf",Activity.MODE_PRIVATE);
		SharedPreferences.Editor editor = sp.edit();
		editor.putString("defaultMsg", str);
		editor.commit();
	}

	public static boolean getMovieEnable(Context context) {
		SharedPreferences sp = context.getSharedPreferences("conf", Context.MODE_PRIVATE);
		boolean mode = sp.getBoolean("movieEnable", true);//默认是进入spa
		return mode;
	}
	
	public static void setMovieEnable(Context context, boolean enable) { 
		SharedPreferences sp= context.getSharedPreferences("conf",Activity.MODE_PRIVATE); 
		SharedPreferences.Editor editor = sp.edit();
		//用putString的方法保存数据 
		editor.putBoolean("movieEnable", enable);
		//提交当前数据 
		editor.commit(); 
	}

	public static String getDebug(Context context) {
		SharedPreferences sp = context.getSharedPreferences("conf", Context.MODE_PRIVATE);
		String mode = sp.getString("debug", DEBUG_OFF);//默认是进入spa
		return mode;
	}
	
	public static void setDebug(Context context, String mode) { 
		SharedPreferences sp= context.getSharedPreferences("conf",Activity.MODE_PRIVATE); 
		SharedPreferences.Editor editor = sp.edit();
		//用putString的方法保存数据 
		editor.putString("debug", mode); 
		//提交当前数据 
		editor.commit(); 
	}

	public static String getAuthToCompany(Context context) {
		SharedPreferences sp = context.getSharedPreferences("conf", Context.MODE_PRIVATE);
		String mode = sp.getString("authToCompany", "");
		return mode;
	}

	//设置授权会所名称
	public static void setAuthToCompany(Context context, String authToCompany){
		SharedPreferences sp = context.getSharedPreferences("conf", Activity.MODE_PRIVATE);
		SharedPreferences.Editor editor = sp.edit();
		//用putString的方法保存数据
		editor.putString("authToCompany", authToCompany);
		//提交当前数据
		editor.commit();
	}

	/*******************开机引导图的本地资源，格式是本地资源的路径**************************/
	public static String getStartUpGuideRes(Context context) {
		SharedPreferences sp = context.getSharedPreferences("spaserverconfig", Context.MODE_PRIVATE);
		String ip = sp.getString("startUpGuideRes", "");
		return ip;
	}
	
	public static void setStartUpGuideRes(Context context, String name) { 
		SharedPreferences sp= context.getSharedPreferences("spaserverconfig",Activity.MODE_PRIVATE); 
		SharedPreferences.Editor editor = sp.edit();
		//用putString的方法保存数据 
		editor.putString("startUpGuideRes", name); 
		//提交当前数据 
		editor.commit(); 
	}	
}
